import { TodoAdd } from '../../action/actionTypes';

const initialState = {
  list: [
    { id: 1, task: '吃饭' },
    { id: 2, task: '睡觉' },
    { id: 3, task: '写代码' },
  ],
};

const todoReducer = (state = initialState, { type, payload }) => {
  switch (type) {
    case TodoAdd:
      return {
        ...state,
        // 💥💥 将payload改成对象数据类型
        list: [...state.list, payload],
      };
    default:
      return state;
  }
};

export default todoReducer;
